package com.gxa.admin.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gxa.admin.mapper.RolesMapper;
import com.gxa.admin.pojo.dto.TRoleDto;
import com.gxa.admin.pojo.vo.TRoleVo;
import com.gxa.admin.service.RoleService;
import com.gxa.admin.utils.QueryResult;
import com.gxa.pojo.TResource;
import com.gxa.pojo.TRole;
import com.gxa.pojo.Vip;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <h3>coffee</h3>
 * <p></p>
 *
 * @author : 你的名字
 * @date : 2024-03-21 09:56
 **/
@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    private RolesMapper rolesMapper;

    /**
     * 查询所有角色
     * @param
     * @return List<TRole>
     */
    @Override
    public List<TRoleVo> showAllRole() {

        return rolesMapper.showAllRole();
    }

    /**
     * 显示角色列表分页)
     * @param
     * @return List<TRole>
     */
    @Override
    public QueryResult showRole(TRoleDto tRoleDto) {

        //分页查询
        Page<TRoleVo> page= PageHelper.startPage(tRoleDto.getPage(), tRoleDto.getLimit());

        //查询所有角色
        List<TRoleVo> tRoles = this.rolesMapper.showAllRole();

        //封装返回数据
        QueryResult queryResult = new QueryResult();
        queryResult.setData(tRoles);
        queryResult.setCount(page.getTotal());

        return queryResult;
    }

    @Override
    public List<TResource> showRoleResourceVoById() {

        return rolesMapper.showRoleResourceVoById();
    }
    @Override
    public Integer updateRole(TRole tRole) {

        return rolesMapper.updateRole(tRole);
    }

    @Override
    public Integer roleAdd(TRoleDto tRoleDto) {
        return rolesMapper.roleAdd(tRoleDto);
    }

    @Override
    public Integer deleteRole(String roleId) {
        return rolesMapper.deleteRole(roleId);
    }
}
